//package com.demo.demo;
//
//import java.util.concurrent.ExecutorService;
//import java.util.concurrent.Executors;
//import java.util.concurrent.LinkedBlockingQueue;
//import java.util.concurrent.CountDownLatch;
//import java.util.concurrent.atomic.AtomicInteger;
//import com.alibaba.druid.util.StringUtils;
//import com.alibaba.fastjson.JSONObject;
//import io.netty.util.internal.StringUtil;
//import okhttp3.HttpUrl;
//
//import java.io.*;
//import java.net.HttpURLConnection;
//import java.net.URL;
//import java.nio.file.Files;
//import java.nio.file.Paths;
//import java.security.*;
//import java.security.spec.InvalidKeySpecException;
//import java.security.spec.PKCS8EncodedKeySpec;
//import java.util.Base64;
//import java.util.HashMap;
//import java.util.LinkedHashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.UUID;
//import java.util.concurrent.CountDownLatch;
//import java.util.concurrent.ExecutorService;
//import java.util.concurrent.Executors;
//import java.util.concurrent.LinkedBlockingQueue;
//import java.util.concurrent.atomic.AtomicInteger;
//
///**
// * @program: management
// * @description:
// * @author: YH
// * @create: 2021-10-08 17:12
// **/
//public class Test {
//
//    public static void main(String[] args) {
//
//
//
//    }
//    private static final int NUM_THREADS = 4;
//    private static final String OUTPUT_FILE = "output.xlsx";
//
//    private LinkedBlockingQueue<List<LinkedHashMap<String, Object>>> thirdDataQueue;
//    private AtomicInteger numProcesses = new AtomicInteger(0);
//
//    public Test(LinkedBlockingQueue<List<LinkedHashMap<String, Object>>> thirdDataQueue) {
//        this.thirdDataQueue = thirdDataQueue;
//    }
//
//    public void processData(List<LinkedHashMap<String, Object>> data) {
//        numProcesses.incrementAndGet();
//
//        try {
//            // Write data to file
//            excelWriter.fill(data, OUTPUT_FILE);
//        } catch (InterruptedException e) {
//            log.error("Error processing data", e);
//        } finally {
//            // Close file
//            excelWriter.close();
//        }
//
//        // Wait for all processes to complete
//        CountDownLatch countDownLatch = new CountDownLatch(numProcesses.get());
//        for (int i = 0; i < NUM_THREADS; i++) {
//            ExecutorService executorService = Executors.newFixedThreadPool(NUM_THREADS);
//            executorService.submit(() -> {
//                try {
//                    countDownLatch.await();
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//            });
//        }
//    }
//
//    private static class ExcelWriter {
//        private static final AtomicInteger rowsWritten = new AtomicInteger(0);
//
//        private FileOutputStream outputStream;
//        private ExcelWriter excelWriter;
//
//        public ExcelWriter(FileOutputStream outputStream) {
//            this.outputStream = outputStream;
//        }
//
//        public void open() throws FileNotFoundException {
//            excelWriter = new ExcelWriter(outputStream);
//        }
//
//        public void close() throws IOException {
//            excelWriter.close();
//            rowsWritten.incrementAndGet();
//        }
//
//        public void fill(List<LinkedHashMap<String, Object>> data, String sheetName) throws InterruptedException, IOException {
//            // Write headers
//            excelWriter.writeSheet("Headers");
//
//            for (LinkedHashMap<String, Object> map : data) {
//                excelWriter.writeRow(map);
//            }
//
//            // Write rows
//            excelWriter.writeSheet("Data");
//            for (int i = 0; i < data.size(); i++) {
//                excelWriter.writeRow(data.get(i));
//            }
//
//            // Wait for all rows to be written
//            CountDownLatch countDownLatch = new CountDownLatch(data.size());
//            for (int i = 0; i < NUM_THREADS; i++) {
//                ExecutorService executorService = Executors.newFixedThreadPool(NUM_THREADS);
//                executorService.submit(() -> {
//                    try {
//                        countDownLatch.await();
//                    } catch (InterruptedException e) {
//                        e.printStackTrace();
//                    }
//                });
//            }
//        }
//    }
//}
